<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>InfoJet Service</title>
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
    <style>
        td
        {
            font-size: 11px;
            font-family: verdana;
        }
        input
        {
            font-size: 11px;
            font-family: verdana;
        }
    </style>
    <base target="_self">
    <!-- //CID //0638 //2010.08.08 //Init -->
</head>
<body style='background-color: BUTTONFACE; padding: 0; margin: 0; '  onload="doLoad()" align="center">
    <script>
        var opener = null;
        var doc = null;
        var hyperlinkBox = null;
        var bsid = null;
        //CID 0641 //2010.11.06 //Begin
        var AddressNotValidText = "The address is not valid. Enter an address that begins with http://, https://, ftp://, mailto:.";
        var InsertHyperlinkText = "Click here to insert a hyperlink";
        //CID 0641 //2010.11.06 //End
        function doLoad() {
            document.title = "Insert Hyperlink";
            opener = window.dialogArguments[0];
            doc = window.dialogArguments[0].document;
            hyperlinkBox = window.dialogArguments[1];
            //CID 0641 //2010.11.06 //Begin
            UseLocalResources();
            //CID 0641 //2010.11.06 //End
            //CID 0664 //2010.11.18 //Begin
            var hyperlink = getHyperlink()
            if (hyperlink != null) {
                document.getElementById("addressBox").value = hyperlink.href;
            }
            //CID 0664 //2010.11.18 //End
            bsid = hyperlinkBox.getAttribute("binding_secondary_id");
            if (bsid != null && bsid.length > 0) {
                //CID 0664 //2010.11.13 //Begin
                if (hyperlink != null) {
                    document.getElementById("textBox").value = hyperlink.innerHTML;
                }
                //CID 0664 //2010.11.18 //End
            } else {
                document.getElementById("textTr").style.display = "none";
            }
        }
        //CID 0641 //2010.11.06 //Begin
        function UseLocalResources() {
            var res = opener.InfoJet_LocalResources["EditLinkDialogResources"];
            if (res != null) {
                document.title = res["Title"];
                document.getElementById("buttonOK").value = res["OK"];
                document.getElementById("buttonCancel").value = res["Cancel"];
                document.getElementById("buttonRemove").value = res["Remove"];
                AddressNotValidText = res["AddressNotValidText"];
                InsertHyperlinkText = res["InsertHyperlinkText"];
                document.getElementById("addressTd").innerHTML = res["AddressText"];
                document.getElementById("exampleTd").innerHTML = res["ExampleText"];
                document.getElementById("displayTextTd").innerHTML = res["DisplayText"];
            }
        }
        //CID 0641 //2010.11.06 //End
        //CID 0664 //2010.11.13 //Begin
        function getHyperlink() {
            var button = opener.InfoJet_GetFirstChild(hyperlinkBox);
            var span = opener.InfoJet_GetNextElement(button);
            var next = opener.InfoJet_GetLastChild(hyperlinkBox);
            //a or span.
            if (next != span) {
                return next;
            }
            return null;
        }
        //CID 0664 //2010.11.18 //End
        function doOK() {
            var address = opener.InfoJet_Trim(document.getElementById("addressBox").value);
            if (address.length > 0) {
                var regexp = /(ftp:\/\/|http:\/\/|https:\/\/|mailto:)(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
                if (!regexp.test(address)) {
                    alert(AddressNotValidText);
                    return;
                }
            }
            var text = opener.InfoJet_Trim(document.getElementById("textBox").value);
            var addressField = opener.InfoJet_GetWriteOnlyField("xdoc" + hyperlinkBox.id);
            addressField.value = address;
            if (bsid != null && bsid.length > 0) {
                var textField = opener.InfoJet_GetWriteOnlyField("xdoc" + bsid);
                textField.value = text;
            }
            if (text.length <= 0) {
                text = address;
            }
            text = text.substr(0, 255);
            var button = opener.InfoJet_GetFirstChild(hyperlinkBox);
            var span = opener.InfoJet_GetNextElement(button);
            var next = opener.InfoJet_GetLastChild(hyperlinkBox);
            //a or span.
            if (next != span) {
                if (address.length <= 0 && text.length <= 0) {
                    opener.InfoJet_RemoveHtmlElement(next);
                    opener.InfoJet_InsertAdjacentHTMLBeforeEnd(hyperlinkBox, InsertHyperlinkText);
                    button.onclick = null;
                    opener.InfoJet_AddHyperlinkBoxOnClick(hyperlinkBox); 
                } else {
                    next.href = address;
                    next.innerHTML = text;
                }
            } else {
                if (address.length <= 0 && text.length <= 0) {
                    //Do nothing.
                } else {
                    hyperlinkBox.onclick = null;
                    opener.InfoJet_AddHyperlinkBoxOnClick(button);
                    //Delete text.
                    next.parentNode.removeChild(next.nextSibling);
                    opener.InfoJet_InsertAdjacentHTMLBeforeEnd(hyperlinkBox, "<a href=" + address + ">" + text + "</a>");
                    var a = opener.InfoJet_GetNextElement(span);
                    a.target = "_blank";
                }
            }
            window.close();
        }
        function doCancel() {
            window.close();
        }
        function doRemove() {
            document.getElementById("addressBox").value = "";
            document.getElementById("textBox").value = "";
        }
    </script>

    <table align="center" height="100%" width="100%" style="margin-left:8px;">
        <tr>
            <td id="addressTd">
                Address:
            </td>
            <td>
                <input type="text" id="addressBox" style="width:100%;"/>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td id="exampleTd">
                Example: http://www.contoso.com/
            </td>
        </tr>
        <tr id="textTr">
            <td id="displayTextTd">
                Display this text:
            </td>
            <td>
                <input type="text" id="textBox" style="width:100%;"/>
            </td>
        </tr>
        <tr>
            <td>
                <input type='button' id="buttonRemove" value='Remove' onclick="doRemove();">
            </td>
            <td align="right">
                <input type='button' id='buttonOK' value='    OK    ' onclick="doOK();">&nbsp;&nbsp;<input type='button' id='buttonCancel' value=' Cancel ' onclick='doCancel();'>
            </td>
        </tr>
    </table>
</body>
</html>
